package exam.web.action.base;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;

import com.opensymphony.xwork2.ActionSupport;

import exam.common.util.ConverUtils;
import exam.model.entity.TUserEntity;
import exam.system.business.BusinessServiceInfo;

/**
 * <p>UserActionBase</p>
 * 
 * @author PhongTN
 * @version 29/4/2012
 */

public class UserActionBase extends ActionSupport 
		implements ServletRequestAware, ServletResponseAware {
	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 1L;
	
	// dinh nghia port FAIL
	public static final String FAIL = "fail";
	
	// request
	protected HttpServletRequest request;
	
	// response
	protected HttpServletResponse response;
	
	// serviceInfo
	protected BusinessServiceInfo serviceInfo = new BusinessServiceInfo();

	@Override
	public void setServletResponse(HttpServletResponse response) {
		// TODO Auto-generated method stub
		this.response = response;
	}

	@Override
	public void setServletRequest(HttpServletRequest request) {
		// TODO Auto-generated method stub
		this.request = request;
	}
	
	/*
	 * ===============================================
	 */
	protected long userId;
	protected String userName;
	protected String password;
	protected String fullName;
	protected Date birthday;
	protected String gender;
	protected String address;
	protected boolean role;
	protected Date createDate;
	protected Date updateDate;
	
	public long getUserId() {
		return userId;
	}
	
	public void setUserId(long userId) {
		this.userId = userId;
	}

	
	public String getUserName() {
		return userName;
	}
	
	public void setUserName(String userName) {
		this.userName = userName;
	}

	
	public String getPassword() {
		return password;
	}
	
	public void setPassword(String password) {
		this.password = password;
	}

	
	public String getFullName() {
		return fullName;
	}
	
	public void setFullName(String fullName) {
		this.fullName = fullName;
	}

	
	public Date getBirthday() {
		return birthday;
	}
	
	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	
	public String getGender() {
		return gender;
	}
	
	public void setGender(String gender) {
		this.gender = gender;
	}

	
	public String getAddress() {
		return address;
	}
	
	public void setAddress(String address) {
		this.address = address;
	}
	
	public Date getCreateDate() {
		return createDate;
	}
	
	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	
	public Date getUpdateDate() {
		return updateDate;
	}
	
	public void setUpdateDate(Date updateDate) {
		this.updateDate = updateDate;
	}

	public boolean isRole() {
		return role;
	}

	public void setRole(boolean role) {
		this.role = role;
	}
	
	/**
	 * copyToTUserEntity
	 * @param tUserEntity
	 */
	public void copyToTUserEntity(TUserEntity tUserEntity) {
		tUserEntity.setUserId(userId);
		tUserEntity.setUserName(userName);
		tUserEntity.setPassword(password);
		tUserEntity.setFullName(fullName);
		tUserEntity.setBirthday(birthday);
		tUserEntity.setGender(gender);
		tUserEntity.setAddress(address);
		tUserEntity.setRole(ConverUtils.converBooleanToInt(role));
	}
	
	/**
	 * copyFromTUserEntity
	 * @param tUserEntity
	 */
	public void copyFromTUserEntity(TUserEntity tUserEntity) {
		userId = tUserEntity.getUserId();
		userName = tUserEntity.getUserName();
		fullName = tUserEntity.getFullName();
		birthday = tUserEntity.getBirthday();
		gender = tUserEntity.getGender();
		address = tUserEntity.getAddress();
		role = ConverUtils.converIntToBoolean(tUserEntity.getRole());
		createDate = tUserEntity.getCreateDate();
		updateDate = tUserEntity.getUpdateDate();
	}
}
